#include "Regex.h"

#include <string.h>
#include <fan-llvm/core/Core.h>
#include "Type.h"
#include "UnsupportedErr.h"


Type* Regex_classType = NULL;
VTable* Regex_classVTable = NULL;


/**********************************************
 *
 * Methods and fields
 *
 **********************************************/


/* Bool equals(Obj? obj) */
Bool Regex_equals(Obj self, NullableObj obj)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.equals not implemented yet"));
}


/* Int hash() */
Int Regex_hash(Obj self)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.hash not implemented yet"));
}


/* Str toStr() */
Str* Regex_toStr(Obj self)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.toStr not implemented yet"));
}


/* Regex fromStr(Str pattern) */
Regex* Regex_fromStr(Str* pattern)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.fromStr not implemented yet"));
}


/* Regex glob(Str pattern) */
Regex* Regex_glob(Str* pattern)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.glob not implemented yet"));
}


/* Bool matches(Str s) */
Bool Regex_matches(Regex* self, Str* s)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.matches not implemented yet"));
}


/* RegexMatcher matcher(Str s) */
RegexMatcher* Regex_matcher(Regex* self, Str* s)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.matcher not implemented yet"));
}


/* Str[] split(Str s, Int limit) */
List* Regex_split_1(Regex* self, Str* s)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.split not implemented yet"));
}


/* Str[] split(Str s, Int limit) */
List* Regex_split(Regex* self, Str* s, Int limit)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Regex.split not implemented yet"));
}


/**********************************************
 *
 * Type-system functions
 *
 **********************************************/


Type* Regex_initType(void)
{
  if (Regex_classType == NULL)
  {
    Type* baseType = Obj_initType();
    VTable* vtable = Regex_initVTable();
    Type* type = Type_new("Regex", baseType, vtable, sizeof(Regex), sizeof(RegexVTable));
    Type_registerMethodImplementation(type, "equals", Regex_equals, 1);
    Type_registerMethodImplementation(type, "fromStr", Regex_fromStr, 1);
    Type_registerMethodImplementation(type, "glob", Regex_glob, 1);
    Type_registerMethodImplementation(type, "hash", Regex_hash, 0);
    Type_registerMethodImplementation(type, "matcher", Regex_matcher, 1);
    Type_registerMethodImplementation(type, "matches", Regex_matches, 1);
    Type_registerMethodImplementation(type, "split", Regex_split_1, 1);
    Type_registerMethodImplementation(type, "split", Regex_split, 2);
    Type_registerMethodImplementation(type, "toStr", Regex_toStr, 0);
    Regex_classType = type;
    Regex_initStatic();
  }
  return Regex_classType;
}


VTable* Regex_initVTable(void)
{
  if (Regex_classVTable == NULL)
  {
    VTable* vtable = memoryAlloc(sizeof(RegexVTable));
    memcpy(vtable, Obj_initVTable(), sizeof(FanObjVTable));
    ((FanObjVTable*)vtable)->equals = Regex_equals;
    ((FanObjVTable*)vtable)->hash = Regex_hash;
    ((FanObjVTable*)vtable)->toStr = Regex_toStr;
    Regex_classVTable = vtable;
  }
  return Regex_classVTable;
}


void Regex_initStatic(void)
{
}
